package de.hdu.pms.ho.dao;

import java.util.List;

import de.hdu.pms.ho.model.Personal;

/**
 * Testclass to test all methods form {@link PersonalDao}
 * @author Dominic Feig
 */
public class PersonalDaoTest extends AbstractDataAccessTest{
	private PersonalDao personalDao;
	private String tableName="Personal";
	public PersonalDao getPersonalDao() {
		return personalDao;
	}
	public void setPersonalDao(PersonalDao personalDao) {
		this.personalDao = personalDao;
	}
	public String getTableName() {
		return tableName;
	}
	public void setTableName(String tableName) {
		this.tableName = tableName;
	}
	public void testFindAll(){//will tested by testFindById()
		personalDao.create("Petra", "Meier");
		personalDao.create("Andrea", "Mueller");
		List<Personal> ganzesPersonal = personalDao.findAll();
		ganzesPersonal.contains(ganzesPersonal);
		
	}
	@SuppressWarnings("deprecation")
	public void testFindById(){
		String[] tables = {tableName};
		personalDao.create("Petra", "Meier");
		personalDao.create("Andrea", "Mueller");
		List<Personal> ganzesPersonal = personalDao.findAll();
		for (Personal personal : ganzesPersonal){
			Integer id = personal.getId();
			Personal found = personalDao.findById(id);
			assertEquals(personal.getNachname(), found.getNachname());
		}
		deleteFromTables(tables);
	}
	@SuppressWarnings("deprecation")
	public void testCreate(){
		personalDao.create("Petra", "Meier");
		int rows = countRowsInTable(tableName);
		assertEquals("Die DB muss eine Zeile enthalten", 1, rows);
	}
	public void testDelete(){
		//cannot be tested, because in the method there is no Id transmitted
	}

}
